<?php
namespace Admin\Controllers;

use Models\User;
use Library\GetRequest;
use Library\Common;

class LoginController extends ControllerBase
{


    /**
     * 用户注册
     */
    public function registerAction()
    {
    }

    /**
     * 用户登录
     */
    public function loginAction()
    {
        if ($this->request->isAjax() && $this->request->isPost()) {
            $param = GetRequest::loginSign(['name', 'pwd']);
            $user = User::findFirst(['name=:name:', 'bind' => ['name' => $param['name']]]);
            $userinfo = $user->toArray();
            if ($userinfo['pwd'] == $this->md5($param['name'], $param['pwd'])) {
                $ip = $this->request->getClientAddress();
                $user->loginTime = TIMESTAMP;
                $user->loginIp = ip2long($ip);
                $user->loginnum = ++$user->loginnum;
                $user->save();
            }
            $this->view->disable();
        }
    }


}

?>